<template>
  <view class="ts-flex ts-column">
    <!-- 弹出窗口 -->
    <view class="ts-mask" v-show="showMask" @click="hide">
      <view class="ts-popup ts-popup-bottom">
        <view class="ts-grid-9">
          <view class="ts-grid-9-item" hover-class="ts-grid-9-item-hover" @tap="navigateTo('add')">
            <ts-icon type="plus" size="80" color="#d81e06"></ts-icon>
            <text class="ts-grid-9-text ts-padding">发布</text>
          </view>
          <view class="ts-grid-9-item" hover-class="ts-grid-9-item-hover" @tap="navigateTo('my')">
            <ts-icon type="person" size="80" color="#d81e06"></ts-icon>
            <text class="ts-grid-9-text ts-padding">我的</text>
          </view>
        </view>
        <button type="warn" style="width: 100%; background-color: #e31436; 	border-radius: 0upx; height: 100upx;" @tap="navigateTo()">确定</button>
      </view>
    </view>
    <!-- 弹出窗口 -->

    <!-- FAB -->
    <view class="ts-fab" @tap="showPopupWindow">
      <image src="../../../../../static/plus.png" />
      <text v-show="messageCount > 0" class="ts-badge ts-badge-danger">{{messageCount}}</text>
    </view>
    <!-- FAB -->

    <ts-banner image='https://via.placeholder.com/750x250' height="250"></ts-banner>

    <ts-search-bar v-model="keywords" @search="doSearch"></ts-search-bar>

    <view class="ts-list">
      <view class="ts-list-cell" hover-class="ts-list-cell-hover" v-for="(item,index) in list" :key="index">
        <view class="ts-media-list">
          <image class="ts-media-list-logo" :src="item.user.head_image"></image>
          <view class="ts-flex ts-flex-item ts-column">
            <view class="ts-flex ts-row" style="justify-content: space-between;">
              <view class="ts-row ts-flex" style="align-items: center;">
                <view class="ts-h4">{{item.user.name}}</view>
                <view class="ts-h5 ts-padding-left">{{item.contact}}</view>
              </view>
              <view class="ts-row ts-flex-item" style="justify-content: flex-end;">
                <ts-badge v-if="item.status.length>0" :type="'success'" :text="item.status"></ts-badge>
                <ts-badge :type="item.type==='丢失'? 'danger':'primary'" :text="item.type"></ts-badge>
              </view>
            </view>
            <view class="ts-flex ts-column ts-flex-item ts-padding-top ts-padding-bottom">
              <text class="ts-flex">{{item.content}}</text>
            </view>
            <view class="ts-row ts-flex" style="flex-wrap: wrap; align-items: center;">
              <image v-for="(img, index2) in item.images" :key="index2" class="image-box" :src="img"></image>
            </view>
            <view class="ts-h5 ts-padding-top">{{item.address}}</view>
            <view class="ts-h5 ts-padding-top">{{item.time}}</view>
          </view>
        </view>
      </view>
    </view>

    <view class="ts-flex ts-column">
      <ts-load-more :loadingType="loadingType"  @tap="getProductList"></ts-load-more>
    </view>

  </view>
</template>

<script>
  import tsBanner from 'components/teaset/components/ts-banner/ts-banner.vue';
  import tsBadge from 'components/teaset/components/ts-badge/ts-badge.vue';
  import tsIcon from 'components/teaset/components/ts-icon/ts-icon.vue';
  import tsSearchBar from 'components/teaset/components/ts-search-bar/ts-search-bar.vue';
  import tsLoadMore from 'components/teaset/components/ts-load-more/ts-load-more.vue';
  import service from 'services/lost-found.js';
  var self;
  export default {
    components: {
      tsBadge,
      tsBanner,
      tsIcon,
      tsSearchBar,
      tsLoadMore
    },
    data() {
      return {
        showMask: false,
        keywords: '',
        messageCount: 1,
        loadingType: 0, //上拉的状态：0-loading前；1-loading中；2-没有更多了
        page: 0,
        list: [],
        // 			list: [{
        // 				user: {
        // 					head_image: 'https://via.placeholder.com/80x80',
        // 					name: '张三丰'
        // 				},
        // 				content: '雨伞',
        // 				type: '捡到',
        // 				time: '13天前',
        // 				address: '西区创业园',
        // 				contact: '13800138000',
        // 				images: [
        // 					'https://via.placeholder.com/350x150',
        // 					'https://via.placeholder.com/350x150',
        // 					'https://via.placeholder.com/350x150',
        // 				]
        // 			}, ]
      }
    },
    async onLoad() {
      self = this;
      await this.doSearch();
    },
    async onReachBottom() {
      console.log("onReachBottom");
      await this.getEventListMoreData();
    },
    methods: {
      showPopupWindow() {
        this.showMask = true;
      },
      hide() {
        this.showMask = false;
      },
      navigateTo(url = '') {
        this.showMask = false;
        if (url) {
          uni.navigateTo({
            url: url
          });
        }
      },
      async doSearch(keywords = '') {
        //重置状态数据
        this.list = [];
        this.page = 0;
        this.loadingType = 0;
        await this.getEventListMoreData();
        // console.log(keywords);
      },
      async getEventListMoreData() {
        //上拉的状态：0-loading前；1-loading中；2-没有更多了
        if (this.loadingType !== 0) {
          return;
        }
        this.loadingType = 1;
        this.page = this.page + 1;
        const data = await service.getEventList(this.keywords, this.page);
        if (data == false) {
          self.loadingType = 2; //2-没有更多了
          return;
        } else {
          self.loadingType = 0; //开启新一轮加载
          self.list = self.list.concat(data);
        }
      }
    }
  };
</script>

<style>
/*  page,
  view {
    display: flex;
    flex-direction: column;
  } */

  .ts-badge {
    margin-right: 20upx;
  }

  .image-box {
    height: 180upx;
    width: 180upx;
    padding-right: 10upx;
    padding-bottom: 10upx;
  }

  .ts-fab {
    position: fixed;
    display: block;
    z-index: 997;
    bottom: 50upx;
    right: 50upx;

    width: 100upx;
    height: 100upx;
    border-radius: 100upx;
    margin: 0 40upx;
    background-color: #e96900;
  }

  .ts-fab image {
    width: 60upx;
    height: 60upx;
    margin: 20upx;
  }

  .ts-fab text {
    position: fixed;
    bottom: 100upx;
    right: 80upx;
  }

  /* 遮罩层 */
  .ts-mask {
    background: rgba(0, 0, 0, 0.6);
    position: fixed;
    width: 100%;
    height: 100%;
    left: 0;
    top: 0;
    z-index: 998;
  }

  /* 弹出层形式的广告 */
  .ts-popup {
    position: fixed;
    display: flex;
    flex-direction: column;
    flex: 1;
    z-index: 999;
    background-color: #ffffff;
    -webkit-box-shadow: 0 0 30upx rgba(0, 0, 0, 0.1);
    box-shadow: 0 0 30upx rgba(0, 0, 0, 0.1);
  }

  .ts-popup-bottom {
    bottom: 0;
    width: 100%;
  }
</style>
